<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=s, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue_2.5.22.js"></script>
  <script src="../vue-router_3.0.2.js"></script>
</head>

<body>
  <div id="app">
    <router-link to='/shop'>商品列表</router-link>
    <router-link to='/register'>注册</router-link>
    <router-view></router-view>
  </div>
  <script>
    var shop = {
      template: `
        <div>
          <h4>商品详情</h4>
          <button @click='handle'>前进</button>
        </div>
      `,
      methods: {
        handle() {
          this.$router.push('/register')
        }
      }

    }

    var Register = {
      template: `
      <div>
        <h4>注册:</h4>
        <button @click='back'>后退</button>
      </div>
      `,
      created() {
        console.log(this.$route.params.id);
      },
      methods: {
        back() {
          this.$router.go(-1)
        }
      }
    }

    const router = new VueRouter({
      routes: [
        { path: '/', redirect: '/shop' },
        { path: '/shop', component: shop, },
        { path: '/register', component: Register }
      ]
    })

    var vm = new Vue({
      el: '#app',
      data: {},
      router
    })
  </script>
</body>

</html>